package app.netant.book.aihu99;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class Aihu99Detail extends BaseDetail {

	public Aihu99Detail(String netSite) {
		super(netSite);
		this.preHref = "http://www.aihu99.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("#wrap #txt99 #main_down #pageMainArea #downInfoArea h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			int idx = title.indexOf("TXT下载");
			if(idx>0){
				title = title.substring(0,idx);
			}
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("#wrap #txt99 #main_down #pageMainArea #downInfoArea .downInfoRowL li");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("#wrap #txt99 #main_down #mainstory #mainSoftIntro");
		if(parts.size()>0){
			String memo = this.getString(parts.get(0).text());
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("#wrap #txt99 #main_down #mainstory ul.downlistbox li.downAddress_li a");
		if(parts.size()>0){
			String url = parts.get(0).attr("href");
			System.out.println("【Url】:"+url);
			Aihu99Detail detail = new Aihu99Detail(url);
			String href = detail.stepHref();
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
	}
	
	public String stepHref(){
		Elements parts = this.select("#wrap #txt99 #Frame "
				+ "table tbody tr td "
				+ "table tbody tr td[bordercolor='#ff9900'][bgcolor='#EBF1E3'][colspan='2'] "
				+ "a.strong.blue");
		if(parts.size()>1){
			String href = parts.get(1).attr("href");
			return href;
		}else if(parts.size()>0){
			String href = parts.get(0).attr("href");
			return href;
		}
		
		return null;
		
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("#wrap #txt99 #main_down #path a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		Aihu99Detail detail = new Aihu99Detail("http://www.aihu99.com/txt/58632.html");
		detail.test();
	}



}
